import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ColorFrame extends JFrame implements ActionListener   {

	public static void main ( String[] args )   {
		ColorFrame colorframe = new ColorFrame ( );
	}

	private CardLayout cards;
	private Container c;
	private JPanel blackpanel, whitepanel, bluepanel, redpanel;
	private JMenuBar menubar;
	private JMenu basic, color;
	private JMenuItem blackitem, whiteitem, blueitem, reditem;

	public ColorFrame ( )   {
		super( "ColorFrame" );

		SetUpPanels();
		SetUpCards();
		SetUpMenus();

		setDefaultCloseOperation ( DISPOSE_ON_CLOSE );      
		setLocation ( 100, 50 );
		setSize ( 500, 500 );
		setVisible ( true );
	}

	public void SetUpPanels()   {
		blackpanel = new JPanel();
		blackpanel.setBackground ( Color.black );
		whitepanel = new JPanel();
		whitepanel.setBackground ( Color.white );
		bluepanel = new JPanel();
		bluepanel.setBackground ( Color.blue );
		redpanel = new JPanel();
		redpanel.setBackground ( Color.red );
	}

	public void SetUpCards()   {
		c = this.getContentPane();
		cards = new CardLayout ( );
		c.setLayout ( cards );
		c.add ( blackpanel, "blackp" );
		c.add ( whitepanel, "whitep" );
		c.add ( bluepanel, "bluep" );
		c.add ( redpanel, "redp" );
	}

	public void SetUpMenus()   {
        	menubar = new JMenuBar ( );
      		setJMenuBar(menubar);

           	basic = new JMenu ( "BASIC" );

            	blackitem = new JMenuItem ( "BLACK" );
            	basic.add ( blackitem );
            	blackitem.addActionListener ( this );
            	basic.addSeparator ( );

            	whiteitem = new JMenuItem ( "WHITE" );
            	basic.add ( whiteitem );
            	whiteitem.addActionListener ( this );

            	menubar.add ( basic );

           	color = new JMenu ( "COLOR" );

            	blueitem = new JMenuItem ( "BLUE" );
            	color.add ( blueitem );
            	blueitem.addActionListener ( this );
            	color.addSeparator ( );

            	reditem = new JMenuItem ( "RED" );
            	color.add ( reditem );
            	reditem.addActionListener ( this );

            	menubar.add ( color );
	}

	public void actionPerformed ( ActionEvent e )   {
		if ( e.getSource ( ) == blackitem )
			cards.show ( c, "blackp" );
		else if ( e.getSource ( ) == whiteitem )
			cards.show ( c, "whitep" );
		else if ( e.getSource ( ) == blueitem )
			cards.show ( c, "bluep" );
		else if ( e.getSource ( ) == reditem )
			cards.show ( c, "redp" );
      	}
}